package com.qww.test07;

public class Test07 {

    public static void main(String[] args) {
        Book book = new Book(true);
        book.checkIn();
        new Book(true);
        System.gc();
    }
}

class Book {

    boolean checkedOut = false;

    Book() { }

    Book(boolean checkOut) {
        checkedOut = checkOut;
    }

    /*
        使用f<code>finalize()</code>方法去检测对象是否真确被清理。
     */
    @Override
    protected void finalize() throws Throwable {
        if (checkedOut) {
            System.out.println("Error : checked out.");
        }
    }

    void checkIn() {
        checkedOut = false;
    }
}
